var editorHtml = "";
$(function() {

	var htm = "<div id=\"editIndex_yinying\" class='yinying' style='z-index:300'></div><div id=\"window_editor\" class=\"hideDiv setHTML\"><textarea id=\"editIndex\" name=\"editIndex\"></textarea><div class=\"BottomBtn\"><input type=\"button\" value=\"确定\" class=\"common_btn\" onclick=\"saveHtml()\" ><input type=\"button\" value=\"取消\" style=\"background-color: red;\" class=\"common_btn\" onclick=\"cancelHtml()\" ></div></div>";
	$("body").prepend(htm);

	$("#editIndex_btn").click(function() {
		editor = KindEditor.create('#editIndex', {
			pasteType : 2,
			height : 400,
			width : 670
		});
		editor.html(editorHtml);
		$("#window_editor,#editIndex_yinying").show();
		addMargin($("#window_editor"));
	});
});

function saveHtml() {
	if (IsEmpty(editor)) {
		editorHtml = "";
	} else {
		editorHtml = editor.html();
	}
	if (window.generateHtmlUrl) {
		generateHtmlUrl();
	}
	editor.remove("#editIndex");
	$("#window_editor,#editIndex_yinying").hide();
}

function cancelHtml() {

	editor.remove("#editIndex");
	$("#window_editor,#editIndex_yinying").hide();
}

function getHtmlByUrl(url) {
	$.ajax({
		type : "get",
		async : false,
		datatype : "json",
		url : "../htmlUtils/find/loadHtml",
		data : {
			'htmlUrl' : url
		},
		success : function(data) {
			var rst = JSON.parse(data);
			if (rst.state == 0) {
				editorHtml = getHeadIndexValue(0, rst, "htmlStr");
			}
		}
	});
}